package com.mercury.ec.module.air.enums;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import com.mercury.ec.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 机票订单状态枚举
 *
 * @author hesx
 */
@Getter
@AllArgsConstructor
public enum AirOrderStatusEnum implements IntArrayValuable {

    CANCELED(0, "已取消"),
    NEW(10, "新订单"),
    WAIT_AUDIT(20, "待审核"),
    REFUSED(25, "已拒绝"),
    WAIT_PAY(30, "待支付（退款）"),
    WAIT_ISSUE(40, "待出（退）票"),
    ISSUING(45, "出（退）票中"),
    ISSUED(50, "已出（退）票"),
    ISSUE_FAIL(55, "出（退）票失败"),
    ;


    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(AirOrderStatusEnum::getStatus).toArray();

    public static final String DICT_TYPE = "air_sale_order_status";

    /**
     * 值
     */
    private final Integer status;
    /**
     * 名称
     */
    private final String name;

    @Override
    public int[] array() {
        return ARRAYS;
    }

    public static AirOrderStatusEnum getByStatus(int status) {
        return ArrayUtil.firstMatch(o -> o.getStatus().equals(status), values());
    }

    public static boolean isCanceled(Integer status) {
        return ObjUtil.equal(CANCELED.status, status);
    }

    public static boolean isNew(Integer status) {
        return ObjUtil.equal(NEW.status, status);
    }

    public static boolean isWaitAudit(Integer status) {
        return ObjUtil.equal(WAIT_AUDIT.status, status);
    }

    public static boolean isRefused(Integer status) {
        return ObjUtil.equal(REFUSED.status, status);
    }

    public static boolean isWaitPay(Integer status) {
        return ObjUtil.equal(WAIT_PAY.status, status);
    }

    public static boolean isWaitIssue(Integer status) {
        return ObjUtil.equal(WAIT_ISSUE.status, status);
    }

    public static boolean isIssuing(Integer status) {
        return ObjUtil.equal(ISSUING.status, status);
    }

    public static boolean isIssued(Integer status) {
        return ObjUtil.equal(ISSUED.status, status);
    }

    public static boolean isIssueFail(Integer status) {
        return ObjUtil.equal(ISSUE_FAIL.status, status);
    }
}
